package cz.muni.fi.pa165.sme.client.converters;

import cz.muni.fi.pa165.sme.client.fo.BurnedCaloriesFO;
import cz.muni.fi.pa165.sportmanager.burnedcaloriesws.BurnedCalories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

/**
 * @author jirankova
 */
public class BurnedCaloriesFO2BurnedCaloriesConverter implements Converter<BurnedCaloriesFO, BurnedCalories> {

	@Autowired
	private SportActivityFO2SportActivityConverter converter;

	@Override
	public BurnedCalories convert(final BurnedCaloriesFO source) {
		if (source == null) {
			return null;
		}

		final BurnedCalories target = new BurnedCalories();
		final Float sourceSpeed = source.getSpeed();
		final Float sourceWeight = source.getWeight();
		final Long sourceCalories = source.getCalories();
		final Long sourceId = source.getId();

		target.setSpeed(sourceSpeed == null ? null : sourceSpeed.toString());
		target.setCalories(sourceCalories == null ? null : sourceCalories.toString());
		target.setId(sourceId == null ? null : sourceId.toString());
		target.setWeight(sourceWeight == null ? null : sourceWeight.toString());

		target.setSportActivity(converter.convert(source.getSportActivity()));

		return target;
	}
}
